
package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import java.awt.event.ActionEvent; 
import javax.sound.sampled.Clip; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JScrollPane; 
import javax.swing.JTextArea; 
import javax.swing.JTextField;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioSystem;
import javax.swing.JOptionPane;

public class NuevoViajeVulto extends javax.swing.JFrame {

 boolean error = false;
 int resultado;
 int enviarcod;
 String tmp;
 javax.sound.sampled.Clip sonido;
 int cantidad=2;
 

    public NuevoViajeVulto(int num) {
        initComponents();
        enviarcod=num;
        cod.setText(""+enviarcod);
   
    }

   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        cfin = new javax.swing.JButton();
        cod = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        cuni = new javax.swing.JTextField();
        ccla = new javax.swing.JTextField();
        cpie = new javax.swing.JTextField();
        ckil = new javax.swing.JTextField();
        clib = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ccon = new javax.swing.JTextArea();
        jButton5 = new javax.swing.JButton();
        numero = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setText("B U L T O ");
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nuevo Viaje ");
        jLabel3.setName("jLabel3"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(636, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel7.setText("Codigo Viaje");
        jLabel7.setName("jLabel7"); // NOI18N

        cfin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        cfin.setText("Finalizar");
        cfin.setEnabled(false);
        cfin.setName("cfin"); // NOI18N
        cfin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfinActionPerformed(evt);
            }
        });

        cod.setText("X");
        cod.setName("cod"); // NOI18N

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        jButton4.setText("Cancelar");
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(143, 0, 0));
        jPanel2.setName("jPanel2"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 760, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 11, Short.MAX_VALUE)
        );

        cuni.setName("cuni"); // NOI18N
        cuni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cuniKeyTyped(evt);
            }
        });

        ccla.setName("ccla"); // NOI18N

        cpie.setName("cpie"); // NOI18N

        ckil.setName("ckil"); // NOI18N

        clib.setName("clib"); // NOI18N

        jPanel3.setBackground(new java.awt.Color(143, 0, 0));
        jPanel3.setName("jPanel3"); // NOI18N

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Unidades");
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setText("Clase de Bulto");
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel13.setText("Contenido");
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel14.setText("Pies Cúbicos");
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel15.setForeground(new java.awt.Color(255, 255, 255));
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Kilos");
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel16.setForeground(new java.awt.Color(255, 255, 255));
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setText("Libras");
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 10));
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("No.");
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(27, 27, 27)
                .addComponent(jLabel8)
                .addGap(18, 18, 18)
                .addComponent(jLabel9)
                .addGap(33, 33, 33)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 231, Short.MAX_VALUE)
                .addComponent(jLabel14)
                .addGap(26, 26, 26)
                .addComponent(jLabel15)
                .addGap(41, 41, 41)
                .addComponent(jLabel16)
                .addGap(75, 75, 75))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
        );

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        ccon.setColumns(20);
        ccon.setLineWrap(true);
        ccon.setRows(5);
        ccon.setName("ccon"); // NOI18N
        jScrollPane2.setViewportView(ccon);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        numero.setText("1");
        numero.setName("numero"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 437, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(cod)
                .addGap(183, 183, 183))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(numero)
                .addGap(35, 35, 35)
                .addComponent(cuni, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cfin, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(64, 64, 64)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(ccla, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(cpie, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ckil, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(clib, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cfin, jButton4});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cod)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ccla, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cuni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(numero)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton5)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(clib, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(ckil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cpie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cfin)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cfin, jButton4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cfinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfinActionPerformed

               
                   try {
                sonido = null;
                sonido = AudioSystem.getClip();
                sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty("user.dir") + "\\src\\SonidosPractica\\Correcto2.wav")));
                sonido.start();




            } catch (Exception e) {
                System.out.println("" + e);
            } // fin

            JOptionPane.showMessageDialog(rootPane, "Viaje ingresado exitosamente");
            dispose();
                 Viaje v;
                 v = new Viaje("SELECT * FROM viaje");
                 v.setVisible(true);
                 v.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
                //
                // voy a editar el kilometraje del camion o cabezal qee se utilzo :D
                 String tipo = NuevoViajePiloto.tipo;
                 if("Camion".equals(tipo)){
                 Error.Mysql("update camion set kilometraje=kilometraje+"+NuevoViajeDatos.kilometraje+" where idcamion="+NuevoViajePiloto.codigovehiculo);
                     
                 }
                 else
                     if("Cabezal".equals(tipo)){
                         Error.Mysql("update cabezal set kilometraje=kilometraje+"+NuevoViajeDatos.kilometraje+" where idcabezal="+NuevoViajePiloto.codigovehiculo);
                 
                     }
                    
                       
    }//GEN-LAST:event_cfinActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
       dispose();
            Error.Mysql("DELETE from viaje where idviaje = "+enviarcod);     
            Error.Mysql("ALTER TABLE viaje auto_increment ="+enviarcod);
            Error.Mysql("DELETE FROM vulto where idviaje="+enviarcod);
            Viaje v;
            v = new Viaje("SELECT * FROM viaje");
            v.setVisible(true);
            v.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
error = false;
// despues qee verifique que los datos esten bien los guardare en nuevo cliente. 
      
        try {
                        Insertar();
                    } catch (FileNotFoundException ex) {
                        Logger.getLogger(NuevoCabezal.class.getName()).log(Level.SEVERE, null, ex);
                    }
    
                    
                    
                 if (!error){
               
                   try {
                sonido = null;
                sonido = AudioSystem.getClip();
                sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty("user.dir") + "\\src\\SonidosPractica\\Correcto2.wav")));
                sonido.start();




            } catch (Exception e) {
                System.out.println("" + e);
            } // fin
                   
            JOptionPane.showMessageDialog(rootPane, "Bulto ingresado exitosamente");
                   if(Integer.parseInt(numero.getText())!= NuevoViajeDatos.cbulto){
                       cuni.setText("");
                       ccla.setText("");
                       ccon.setText("");
                       cpie.setText("");
                       ckil.setText("");
                       clib.setText("");
                       numero.setText(""+cantidad++);
                   }
                   else {
                       cuni.setEnabled(false);
                       ccla.setEnabled(false);
                       ccon.setEnabled(false);
                       cpie.setEnabled(false);
                       ckil.setEnabled(false);
                       clib.setEnabled(false);
                       numero.setText(""+"FIN");
                       cfin.setEnabled(true);
                   }
                    
                 }                
                                            
    }//GEN-LAST:event_jButton5ActionPerformed

    private void cuniKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cuniKeyTyped
            char c = evt.getKeyChar();
      if (!(Character.isDigit(c) || (c == evt.VK_BACK_SPACE) || (c == evt.VK_DELETE) || ((c== evt.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cuniKeyTyped

 
    public void Insertar() throws FileNotFoundException{
     
    try {
           

            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
         
            // coneccion
            Connection conexion = (Connection) dataSource.getConnection();
            

            PreparedStatement ps = null;
             ps = (PreparedStatement) conexion.prepareStatement("Insert into vulto (unidades,clase_de_vulto,contenido,pies_cubicos,kilos,libras,idvehiculo,tipovehiculo,idviaje) values (?,?,?,?,?,?,?,?,?)");
            
  // PRIMER CAMPO 
             

       
             
            try{
           ps.setInt(1, Integer.parseInt(cuni.getText()));
         }catch (Exception e) {
             
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el campo unidades del bulto, no es un dato númerico.");
         }
             
          
 // SEGUNDO CAMPO 
            if (!ccla.getText().equals("")) {

                 ps.setString(2,ccla.getText());
                 
            }
            else{
                
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el campo clase de bulto, dato vació.");
                
            }
          
// TERCER CAMPO 
            if(ccon.getText() != null){
                 ps.setString(3,ccon.getText());
                 
            }
            else{
                
                JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el campo contenido del bulto, dato vació.");
                
            }
            
// CUARTO CAMPO 
           
            int pc =0; 
            
             try{
          pc= Integer.parseInt(cpie.getText());
         }catch (Exception e) {
             pc=0;
         }
               ps.setInt(4,pc); 
// QUINTO CAMPO 
            
            int kg=0;          
             try{
                  kg= Integer.parseInt(ckil.getText());
             
         }catch (Exception e) {
                kg=0;
         }
            ps.setInt(5,kg);
// SEXTO CAMPO   
        
      int lb = 0;
     
             try{
            lb= Integer.parseInt(clib.getText());     
            ps.setInt(6,lb); 
         }catch (Exception e) {
             if(lb==0&&kg==0&&pc==0){
                  JOptionPane.showMessageDialog(rootPane, "Debe ingresar alguna medida, ya sea piés, kilos ó libras");
         
             }
             else{
                 lb=0;
                 ps.setInt(6,lb);
                 
             }
            }
// SEPTIMO CAMPO 
     
             try{
            ps.setInt(7,NuevoViajePiloto.codigovehiculo); 
         }catch (Exception e) {
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el campo codigovehiculo,  no es un dato númerico.");
         }       
// OCTAVO CAMPO 
             
            ps.setString(8,NuevoViajePiloto.tipo); 
// NOVENO CAMPO 
              try{
            ps.setInt(9,enviarcod); 
         }catch (Exception e) {
             JOptionPane.showMessageDialog(rootPane, "Dato erroneo en el campo codigo viaje,  no es un dato númerico.");
         }     
            
            
             resultado = ps.executeUpdate();
             
            
// sonido

               conexion.close(); // cierro la conexion
               ps.close();

             }catch(SQLException e){
             JOptionPane.showMessageDialog(rootPane,"Error en Programa:"+e);
         
           
            error = true;
            
           } // fin del catch
}
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NuevoViajeCliente().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ccla;
    private javax.swing.JTextArea ccon;
    private javax.swing.JButton cfin;
    private javax.swing.JTextField ckil;
    private javax.swing.JTextField clib;
    public static javax.swing.JLabel cod;
    private javax.swing.JTextField cpie;
    private javax.swing.JTextField cuni;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane2;
    public static javax.swing.JLabel numero;
    // End of variables declaration//GEN-END:variables
}
